import java.util.ArrayList;
import java.util.List;

class Solution {
    public List<Integer> findAnagrams(String s, String p) {
        int size=p.length();
        List<Integer> list=new ArrayList();
        int[] arr=new int[26];
        char c=0;
        for(int i=0;i<size;i++){
            c=p.charAt(i);
            arr[c-97]++;

        }

        int right=0;
        int left=0;
        int count=0;
        while(right<s.length()){
            c=s.charAt(right);


            if(arr[c-97]!=0){
                arr[c-97]--;

                count++;
            }else{
                c=s.charAt(left);
                arr[c-97]++;
                left++;
                count--;
                continue;
            }

            if(count==size){
                list.add(left);
                c=s.charAt(left);
                arr[c-97]++;
                left++;
                count--;
            }
            right++;
        }
        return list;


    }
}